package com.server.test.main;

import com.server.test.pojo.AccessToken;
import com.server.test.pojo.Button;
import com.server.test.pojo.CommonButton;
import com.server.test.pojo.ComplexButton;
import com.server.test.pojo.Menu;
import com.server.test.pojo.ViewButton;
import com.server.test.util.WeixinUtil;

/**
 * 菜单管理器类
 * 
 */
public class MenuManager {
	
	public static final String APP_ID = "wx0692fa375d68142f";
	public static final String APP_SECRET = "889ba2cae0b27043dbcf3b5520c05a5a";

	public static void main(String[] args) {
		// 调用接口获取access_token
		AccessToken at = WeixinUtil.getAccessToken(APP_ID, APP_SECRET);
		if (null != at) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), at.getToken());
			// 判断菜单创建结果
			if (0 == result){
				
			}else{
			}
		}
	}

	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	private static Menu getMenu() {
		return getViewMenu(); 
	}
	
	
	
	
	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	private static Menu getViewMenu() {
		
		CommonButton btn21 = new CommonButton();
		btn21.setName("单品");
		btn21.setType("click");
		btn21.setKey("21");

		CommonButton btn22 = new CommonButton();
		btn22.setName("280自助");
		btn22.setType("click");
		btn22.setKey("22");

		CommonButton btn23 = new CommonButton();
		btn21.setName("398自助");
		btn21.setType("click");
		btn21.setKey("21");

		 
		ViewButton btn11 = new ViewButton();
		btn11.setName("预约");
		btn11.setType("view");
		btn11.setUrl("http://zhaoweiserver.sinaapp.com/weixin/reservation/reservation.jsp");

		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("预约");
		mainBtn1.setSub_button(new Button[] { btn11});

		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("菜单");
		mainBtn2.setSub_button(new Button[] { btn21, btn22, btn23 });

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("优惠券");
		mainBtn3.setSub_button(new Button[] { btn21, btn22, btn23 });

		 
		Menu menu = new Menu();
		menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });

		return menu;
	}
}
